/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tubes5progin.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import tools.constants;
import tools.debug;

/**
 *
 * @author Rezha
 */
public class server {
    //variable-variable

    public int maxConnection = 100;
    //port
    public int port = constants.port;
    public int currentConnection = 0;

    public static void main(String args[]) {
        int i = 0;
        server s = new server();
        try {
            ServerSocket listener = new ServerSocket(s.port);
            Socket server;
            while (s.currentConnection++ < s.maxConnection || s.maxConnection == 0) {
                System.out.println("Server Start, Menunggu koneksi ke: " + s.currentConnection);
                server = listener.accept();
                serverHandler clientHandler = new serverHandler(server, s);
                Thread t = new Thread(clientHandler);
                t.start();
            }

        } catch (IOException ex) {
            debug.debugCode("IO Exception Occured");
            Logger.getLogger(server.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
